<template>
<div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="padding-left:15px;width:100%">
        <el-form :inline="true" :model="filters" :size="size">
            <el-row class="search-input">
                <el-form-item label="商品名称：">
                    <el-input v-model="filters.chineseName" placeholder="商品名称" clearable />
                </el-form-item>
                <el-form-item label="商品编码：">
                    <el-input v-model="filters.code" placeholder="商品编码" clearable />
                </el-form-item>
                <el-form-item label="商品品牌：">
                    <el-input v-model="filters.brandName" placeholder="商品品牌" clearable />
                </el-form-item>
                <el-form-item label="商品类目：">
                    <el-select v-model="productCategory" placeholder="商品类目" clearable>
                        <el-option value="" :label="productCategory" style="height: 27vh; background-color:#fff">
                            <el-tree :data="categoryData" :highlight-current="true" :props="defaultProps" node-key="id" @node-click="thisTreeClick" ref="tree"></el-tree>
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="商品类型：">
                    <el-select v-model="filters.type" clearable placeholder="商品类型">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="实体商品" value="1"></el-option>
                        <el-option label="虚拟商品" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="商品形式：">
                    <el-select v-model="filters.typeOfProduct" style="width:200px" clearable placeholder="商品形式">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="普通商品" value="1"></el-option>
                        <el-option label="系列子品" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="店铺：" label-width="93px">
                    <el-input v-model="filters.storeName" placeholder="店铺" clearable />
                </el-form-item>
            </el-row>

            <!--查询,重置-->
            <el-row class="search-button button20">
                <el-form-item>
                    <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="findPage(null)" />
                </el-form-item>
                <el-form-item>
                    <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleBatchPrice">批量修改价格</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleBatchStock">批量设置库存</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-upload2" @click="batchPriceImport">批量价格导入</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-download" @click="batchPriceExport">批量价格导出</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-upload2" @click="batchStockImport">批量库存导入</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-download" @click="batchStockExport">批量库存导出</el-button>
                </el-form-item>
            </el-row>

            <!--上下架-->
            <el-row class="t_r">
                <el-radio-group v-model="activeName" @change="handleClick" style="margin-bottom: 20px;" size="small">
                    <el-radio-button label="first">全部</el-radio-button>
                    <el-radio-button label="second">上架</el-radio-button>
                    <el-radio-button label="third">下架</el-radio-button>
                </el-radio-group>
            </el-row>
        </el-form>
    </div>

    <!--表格内容栏-->
    <cy-table :height="350" :highlightCurrentRow="true" :content="pageResult" :totalSize="totalSize" :columns="columns" :showOverflowTooltip="true" :showSelection="false" :showBatchDelete="false" :showDetailOperation="false" :showDeleteOperation="false" @findPage="findPage" @handleEdit="handleEdit" ref="CyTable"></cy-table>

    <!--编辑店铺商品-->
    <el-dialog title="编辑店铺商品" width="80%" :visible.sync="editDialogVisible" :close-on-click-modal="false">
        <el-form :model="dataForm" label-width="80px" :rules="dataFormRules" ref="dataForm" :inline="true" :size="size">
            <el-form-item label="商品id：" prop="id" v-show="false">
                <el-input v-model="dataForm.id"></el-input>
            </el-form-item>
            <el-form-item label="店铺：" prop="deptId">
                <el-select v-model="dataForm.deptId" :disabled="true">
                    <el-option v-for="item in queryStoreList" :key="item.deptId" :label="item.storeName" :value="item.deptId"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="渠道：" prop="channelName">
                <el-input v-model="dataForm.channelName" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="运费模板：" prop="freightTemplateId">
                <el-select v-model="dataForm.freightTemplateId">
                    <el-option v-for="item in queryFreightTemplate" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>

        <el-table :data="getProductParentList" :size="size" header-align="center" align="center" style="width:100%;" :header-cell-style="{ 'color': '#FFF','background-color': '#2F4554'}">
            <el-table-column v-for="(item, index) in getProductParentAttrList" :key="item.attrId" :label="item.attrName">
                <template slot-scope="scope">{{scope.row.productPropertyResponseList[index].valueName}}</template>
            </el-table-column>
            <el-table-column label="商品编码" prop="code"></el-table-column>
            <el-table-column label="销售计量单位" prop="unitsName"></el-table-column>
            <el-table-column label="库存数量（件）" width="200">
                <template slot-scope="scope">
                    <el-col></el-col>
                    <el-input v-model="scope.row.availableStock">
                        <template slot="prepend">可售</template>
                    </el-input>
                    <el-input v-if="scope.row.warehousingFlag==0" v-model="scope.row.dayStock">
                        <template slot="prepend">每日库存</template>
                    </el-input>
                    <el-input v-model="scope.row.blockStock" :disabled="true">
                        <template slot="prepend">冻结</template>
                    </el-input>

                </template>
            </el-table-column>
            <el-table-column label="外部商品编码" prop="thirdProductCode">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.thirdProductCode" style="width: 100px"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="售价" prop="salePriceWithTax">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.salePriceWithTax" style="width: 100px" :disabled="scope.row.isAudit != 0"></el-input>
                    <el-tooltip style="font-size: 20px;" effect="light" :enterable="false" placement="right" v-if="scope.row.isAudit != 0">
                        <div slot="content" style="min-width: 200px; min-height: 80px;">
                            <p>价格正在审核中......</p>
                            <p>发起人: {{scope.row.creator}}</p>
                            <p>修改时间: {{scope.row.createTime}}</p>
                        </div>
                        <i class="el-icon-question" />
                    </el-tooltip>
                </template>
            </el-table-column>
            <el-table-column label="市场价" prop="marketPrice">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.marketPrice" style="width: 100px"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="采购价" prop="purchasePriceWithTax">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.purchasePriceWithTax" style="width: 100px"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="团购价" prop="groupBuyingPrice">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.groupBuyingPrice" style="width: 100px"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="上下架状态" prop="canSale" width="150">
                <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.canSale">
                        <el-radio :label="1">上架</el-radio>
                        <el-radio :label="0">下架</el-radio>
                    </el-radio-group>
                </template>
            </el-table-column>
        </el-table>

        <div slot="footer" class="dialog-footer" style="text-align:center">
            <el-button :size="size" @click.native="editDialogVisible = false">{{$t('action.cancel') }}</el-button>
            <el-button :size="size" type="primary" @click.native="submitForm" :loading="editLoading">{{ $t('action.submit')}}</el-button>
        </div>
    </el-dialog>

    <!--批量修改价格-->
    <el-dialog title="批量修改价格" width="80%" :visible.sync="batchPriceDialogVisible" :close-on-click-modal="false">
        <el-form :model="priceFilters" label-width="80px" ref="priceFilters" :inline="true" :size="size">
            <el-form-item>
                <el-input v-model="priceFilters.chineseName" placeholder="商品名称" clearable>
                    <template slot="append">
                        <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="batchPriceQuery()" />
                    </template>
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-input v-model="num" type="number" min="0" @input="inputPriceChange" placeholder="商品价格" clearable>
                    <template slot="append">
                        <kt-button icon="fa fa-edit" label="批量修改" :size="size" @click="handleBatchPriceSubmit()" />
                    </template>
                </el-input>
            </el-form-item>
        </el-form>

        <el-table :data="getPriceProductList" header-align="center" align="center" style="width:100%;" :size="size" :header-cell-style="{ 'color': '#FFF','background-color': '#2F4554'}">
            <el-table-column label="商品ID" prop="id"></el-table-column>
            <el-table-column label="商品名称" prop="chineseName"></el-table-column>
            <el-table-column label="商品品牌" prop="brandName"></el-table-column>
            <el-table-column label="售价" prop="salePriceWithTax">
                <template slot-scope="scope">
                    <el-input type="text" v-model="scope.row.salePriceWithTax"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="市场价" prop="marketPrice"></el-table-column>
            <el-table-column label="店铺名称" prop="storeName"></el-table-column>
        </el-table>

        <div slot="footer" class="dialog-footer" style="text-align:center">
            <el-button :size="size" @click.native="handlePriceCancel()">{{$t('action.cancel') }}</el-button>
        </div>
    </el-dialog>

    <!--批量设置库存-->
    <el-dialog title="批量设置库存" width="80%" :visible.sync="batchStockDialogVisible" :close-on-click-modal="false">
        <el-form :model="stockFilters" ref="stockFilters" label-width="80px" :inline="true" :size="size">
            <el-form-item>
                <el-input v-model="stockFilters.chineseName" placeholder="商品名称" clearable>
                    <template slot="append">
                        <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="batchStockQuery()" />
                    </template>
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-input v-model="num" type="number" min="0" @input="inputStockChange" placeholder="商品总库存" clearable>
                    <template slot="append">
                        <kt-button icon="fa fa-edit" label="批量修改" :size="size" @click="handleBatchStockSubmit()" />
                    </template>
                </el-input>
            </el-form-item>
        </el-form>

        <el-table :data="getStockProductList" style="width:100%;" header-align="center" align="center" :size="size" :header-cell-style="{ 'color': '#FFF','background-color': '#2F4554'}">
            <el-table-column label="商品ID" prop="id"></el-table-column>
            <el-table-column label="商品名称" prop="chineseName"></el-table-column>
            <el-table-column label="商品品牌" prop="brandName"></el-table-column>
            <el-table-column label="总库存" prop="totalStock">
                <template slot-scope="scope">
                    <el-input type="text" v-model="scope.row.totalStock"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="店铺名称" prop="storeName"></el-table-column>
        </el-table>

        <div slot="footer" class="dialog-footer" style="text-align:center">
            <el-button :size="size" @click.native="handleStockCancel()">{{$t('action.cancel') }}</el-button>
        </div>
    </el-dialog>

    <!--批量修改库存-->
    <el-dialog title="批量修改库存" width="30%" height="30%" :visible.sync="showAddDialog" :close-on-click-modal="false" center>
        <el-upload class="upload-demo" ref="upload" :action="uploadExcel()" :on-success="handleSuccess" name="file" :file-list="fileList" :before-upload="beforeUpload" :auto-upload="false">
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">批量导入</el-button>
            <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
        </el-upload>
    </el-dialog>

    <!--批量修改价格-->
    <el-dialog title="批量修改价格" width="30%" height="30%" :visible.sync="showAddDialog" :close-on-click-modal="false" center>
        <el-upload class="upload-demo" ref="uploadPrice" :action="uploadExcelPrice()" :on-success="handleSuccess" name="file" :file-list="fileList" :before-upload="beforeUpload" :auto-upload="false">
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUploadPrice">批量导入</el-button>
            <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
        </el-upload>
    </el-dialog>
</div>
</template>

<script>
import CyTable from "@/views/Core/ProductTable";
import KtButton from "@/views/Core/KtButton";
import { format, formatDate2 } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import axios from "axios";

export default {
  components: {
    KtButton,
    CyTable,
    TableColumnFilterDialog
  },

  data() {
    return {
      queryStoreList: [],
      size: "small",
      activeName: "first",
      productCategory: "",
      filters: {
        chineseName: "",
        code: "",
        brandName: "",
        productCategoryId: 0,
        canSale: "",
        type: "",
        typeOfProduct: "",
        storeName: ""
      },
      totalSize: 0,
      pageResult: [],
      categoryData: [],
      defaultProps: {
        children: "categoryList",
        label: "name"
      },
      columns: [
        {
          prop: "id",
          label: "商品ID",
          minWidth: 120
        },
        {
          prop: "pictureUrl",
          label: "主图",
          minWidth: 120,
          showImg: true
        },
        {
          prop: "chineseName",
          label: "商品名称",
          minWidth: 120
        },
        {
          prop: "typeOfProduct",
          label: "商品形式",
          minWidth: 100,
          formatter: this.formatTypeOfProduct
        },
        {
          prop: "code",
          label: "商品编码",
          minWidth: 120
        },
        {
          prop: "totalStock",
          label: "总库存",
          minWidth: 100
        },
        {
          prop: "brandName",
          label: "商品品牌",
          minWidth: 100
        },
        {
          prop: "fullNamePath",
          label: "商品类目",
          minWidth: 120
        },
        {
          prop: "canSale",
          label: "上下架状态",
          minWidth: 120,
          formatter: function(row, column, prop) {
            // 上下架状态 0-下架，1-上架
            if (prop === 0) {
              return "下架";
            } else if (prop === 1) {
              return "上架";
            }
          }
        },
        {
          prop: "type",
          label: "商品类型",
          minWidth: 100,
          formatter: function(row, column, prop) {
            if (prop == 1) {
              return "实体商品";
            } else if (prop == 2) {
              return "虚拟商品";
            }
          }
        },
        {
          prop: "productUnit",
          label: "计量单位",
          minWidth: 100
        },
        {
          prop: "salePriceWithTax",
          label: "售价",
          minWidth: 120
        },
        {
          prop: "marketPrice",
          label: "市场价",
          minWidth: 120
        }
      ],
      pageRequest: {
        pageNum: 1,
        pageSize: 10
      },
      queryFreightTemplate: [], // 运费模板
      getProductParentList: [],
      getProductParentAttrList: [],
      editLoading: false,
      editDialogVisible: false, // 新增编辑界面是否显示
      dataFormRules: {
        freightTemplateId: [
          {
            required: true,
            message: "请输入运费模板",
            trigger: "change"
          }
        ]
      },
      dataForm: {
        id: "",
        deptId: "",
        channelName: "",
        freightTemplateId: ""
      },

      num: "", // 商品价格或者库存
      batchPriceDialogVisible: false, // 批量修改价格
      priceFilters: {},
      getPriceProductList: [],

      batchStockDialogVisible: false, // 批量修改库存
      stockFilters: {},
      getStockProductList: [],

      showAddDialog: false,
      fileList: [],
      fileListPrice: []
    };
  },

  mounted() {
    this.queryBehindCategory();
    this.queryFreightTemplateData();
    this.queryStoreListData();
  },

  methods: {
    // 店铺
    queryStoreListData() {
      let this_ = this;
      let param = {};
      this.utils.request.queryStoreList(param, function(data) {
        if (data.data != null) {
          this_.queryStoreList = data.data;
        }
      });
    },

    // 下拉树查询所有商品类目
    queryBehindCategory: function() {
      let params = {};
      let this_ = this;
      this.utils.request.queryBehindCategory(params, function(data) {
        this_.categoryData = data.data;
      });
    },

    // 运费模板下拉框
    queryFreightTemplateData() {
      let this_ = this;
      this.utils.request.queryFreightTemplate({}, function(data) {
        if (data.data) {
          this_.queryFreightTemplate = data.data;
        }
      });
    },

    beforeUpload(file) {},

    uploadExcel() {
      return "http://52.130.80.160:8089/productExcel/byExcelUpdateProductStock";
    },

    uploadExcelPrice() {
      return "http://52.130.80.160:8089/productExcel/byExcelUpdateProductPrice";
    },

    //提交模板
    submitUpload() {
      this.$refs.upload.submit();
    },

    submitUploadPrice() {
      this.$refs.uploadPrice.submit();
    },

    handleSuccess: function(res) {
      if (res.code == "0000") {
        this.$message({
          message: res.data,
          type: "success"
        });
        this.showAddDialog = false;
      } else {
        this.$message({
          message: "操作失败, " + res.msg,
          type: "error"
        });
      }
    },

    // 批量价格导入
    batchPriceImport: function() {
      this.fileListPrice = [];
      this.showAddDialog = true;
    },

    // 批量导出价格
    batchPriceExport: function() {
      axios({
        method: "post",
        url: "http://52.130.80.160:8089/productExcel/shopProductPriceExcel",
        data: {},
        responseType: "blob"
      })
        .then(res => {
          console.log(res);
          const link = document.createElement("a");
          let blob = new Blob([res.data], {
            type: "application/vnd.ms-excel"
          });
          link.style.display = "none";
          link.href = URL.createObjectURL(blob);
          link.setAttribute(
            "download",
            "商品价格_" + formatDate2(new Date()) + ".xls"
          );
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
        .catch(error => {
          this.$Notice.error({
            title: "错误",
            desc: "网络连接错误"
          });
          console.log(error);
        });
    },

    // 批量导入库存
    batchStockImport() {
      this.fileList = [];
      this.showAddDialog = true;
    },

    // 批量导出库存
    batchStockExport() {
      axios({
        method: "post",
        url: "http://52.130.80.160:8089/productExcel/shopProductStockExcel",
        data: {},
        responseType: "blob"
      })
        .then(res => {
          console.log(res);
          const link = document.createElement("a");
          let blob = new Blob([res.data], {
            type: "application/vnd.ms-excel"
          });
          link.style.display = "none";
          link.href = URL.createObjectURL(blob);
          link.setAttribute(
            "download",
            "商品库存_" + formatDate2(new Date()) + ".xls"
          );
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
        .catch(error => {
          this.$Notice.error({
            title: "错误",
            desc: "网络连接错误"
          });
          console.log(error);
        });
    },

    // 批量查询价格
    batchPriceQuery() {
      let this_ = this;
      this_.priceFilters.start = 1;
      this_.priceFilters.limit = 999;
      this_.priceFilters.warehousingFlag = 1;
      this_.utils.request.queryShopApi(this.priceFilters, function(res) {
        this_.getPriceProductList = res.data.rows;
      });
    },

    // 批量修改价格弹窗
    handleBatchPrice() {
      let this_ = this;
      this_.batchPriceDialogVisible = true;
      this_.batchPriceQuery();
    },

    // 动态改变价格
    inputPriceChange(val) {
      if (val !== "" && val >= 0) {
        this.getPriceProductList.forEach(item => {
          item.salePriceWithTax = val;
        });
      }
    },

    // 批量修改价格提交
    handleBatchPriceSubmit() {
      if (this.getPriceProductList.length === 0) {
        return this.$message({
          message: "暂无商品价格可修改",
          type: "error"
        });
      }
      if (this.num === "") {
        return this.$message({
          message: "请填写商品价格",
          type: "error"
        });
      }
      let obj = {};
      let productBatchUpdateRequestList = [];
      this.getPriceProductList.forEach(item => {
        let list = {};
        list.id = item.id;
        list.num = item.salePriceWithTax;
        productBatchUpdateRequestList.push(list);
      });
      obj.productBatchUpdateRequestList = productBatchUpdateRequestList;
      let this_ = this;
      this_.utils.request.batchUpdateProductPrice(obj, function(data) {
        if (data.code === "0000") {
          this_.$message({
            message: "操作成功",
            type: "success"
          });
        } else {
          this_.$message({
            message: "操作失败, " + data.msg,
            type: "error"
          });
        }
      });
    },

    // 批量修改价格取消
    handlePriceCancel() {
      this.batchPriceDialogVisible = false;
      this.priceFilters = {};
      this.num = "";
    },

    // 批量库存查询
    batchStockQuery() {
      let this_ = this;
      this_.stockFilters.start = 1;
      this_.stockFilters.limit = 999;
      this_.stockFilters.warehousingFlag = 1;
      this_.utils.request.queryShopApi(this.stockFilters, function(res) {
        this_.getStockProductList = res.data.rows;
      });
    },

    // 批量修改库存弹窗
    handleBatchStock() {
      this.batchStockDialogVisible = true;
      this.batchStockQuery();
    },

    // 动态改变总库存
    inputStockChange(val) {
      if (val !== "" && val >= 0) {
        this.getStockProductList.forEach(item => {
          item.totalStock = val;
        });
      }
    },

    // 批量修改库存提交
    handleBatchStockSubmit() {
      if (this.getStockProductList.length === 0) {
        return this.$message({
          message: "暂无商品总库存可修改",
          type: "error"
        });
      }
      if (this.num === "") {
        return this.$message({
          message: "请填写商品总库存",
          type: "error"
        });
      }
      let obj = {};
      let productBatchUpdateRequestList = [];
      this.getStockProductList.forEach(item => {
        let list = {};
        list.id = item.id;
        list.num = item.totalStock;
        productBatchUpdateRequestList.push(list);
      });
      obj.productBatchUpdateRequestList = productBatchUpdateRequestList;
      let this_ = this;
      this.utils.request.batchUpdateProductStock(obj, function(data) {
        if (data.code == "0000") {
          this_.$message({
            message: "操作成功",
            type: "success"
          });
        } else {
          this_.$message({
            message: "操作失败, " + data.msg,
            type: "error"
          });
        }
      });
    },

    // 批量库存取消
    handleStockCancel() {
      this.batchStockDialogVisible = false;
      this.stockFilters = {};
      this.num = "";
    },

    // tab切换
    handleClick(val) {
      if (val == "first") {
        this.filters.canSale = null;
        this.findPage(1);
      } else if (val == "second") {
        this.filters.canSale = 1;
        this.findPage(1);
      } else if (val == "third") {
        this.filters.canSale = 0;
        this.findPage(1);
      }
    },

    // 下拉树点击事件
    thisTreeClick: function(data, checked) {

      // 指定节点是否为叶子节点
      if (checked.isLeaf) {
        this.filters.productCategoryId = data.id;
        this.productCategory = data.name;
      }
    },

    // 获取分页数据
    findPage: function(params) {

      let this_ = this;
      if (params == undefined || params == null) {
        params = {
          pageNum: this_.pageRequest.pageNum,
          pageSize: this_.pageRequest.pageSize
        };
      }
      if (this_.filters == undefined || this_.filters == null) {
        this_.filters = {};
      }
      this_.filters.start = params.pageNum;
      this_.filters.limit = params.pageSize;
      this.utils.request.queryShopApi(this_.filters, function(res) {
        this_.pageResult = res.data.rows;
        this_.totalSize = Number(res.data.total);
      });
    },

    // 显示编辑界面
    handleEdit: function(data) {
      let this_ = this;
      this_.editDialogVisible = true;
      let params = {};
      params.productId = data.row.id;
      this.utils.request.getProductParent(params, function(res) {
        this_.dataForm = {
          id: res.data[0].id,
          deptId: Number(res.data[0].deptId),
          channelName: res.data[0].channelName,
          freightTemplateId: res.data[0].freightTemplateId
        };
        this_.getProductParentList = res.data;
        $.each(res.data, function(index, val) {
          if (index == 0) {
            this_.getProductParentAttrList =
              res.data[index].productPropertyResponseList;
            return;
          }
        });
      });
    },

    // 编辑
    submitForm: function() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          var this_ = this;
          let params = {};
          let productDistributeStoreParentRequests = [];
          params.productId = this_.dataForm.id;
          params.storeId = this_.dataForm.storeIdOne;
          params.freightTemplateId = this_.dataForm.freightTemplateId;
          $.each(this_.getProductParentList, function(index, val) {
            if (val != null && val != "") {
              let list = {};
              list.productId = val.id;
              list.salePriceWithTax = val.salePriceWithTax;
              list.groupBuyingPrice = val.groupBuyingPrice;
              list.marketPrice = val.marketPrice;
              list.purchasePriceWithTax = val.purchasePriceWithTax;
              list.canSale = val.canSale;
              list.isAudit = val.isAudit;
              list.unitsName = val.unitsName;
              list.availableStock = val.availableStock;
              list.dayStock = val.dayStock;
              list.thirdProductCode = val.thirdProductCode;
              productDistributeStoreParentRequests.push(list);
            }
          });
          params.productDistributeStoreParentRequests = productDistributeStoreParentRequests;
          this.utils.request.updateProductDistributeStore(params, function(
            res
          ) {
            if (res.code == "0000") {
              this_.$message({
                message: "操作成功",
                type: "success"
              });
              this_.$refs["dataForm"].resetFields();
              this_.editDialogVisible = false;
              this_.findPage(null);
            } else {
              this_.$message({
                message: "操作失败, " + res.msg,
                type: "error"
              });
            }
          });
        }
      });
    },

    // 重置
    resetForm() {
      this.filters = {};
      this.activeName = "first";
      this.productCategory = "";
      this.findPage();
    },
    formatTypeOfProduct: function(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "普通商品";
      } else if (cellValue == 2) {
        return "系类虚品";
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.el-tabs el-tabs--card el-tabs--top {
  height: 9vh;
}
</style>
